fix: show the soft keyboard when a long-press starts text selection in TextInput on Android#57471
fix: show the soft keyboard when a long-press starts text selection in TextInput on Android#57471idoyana wants to merge 1 commit into
Conversation
…Input on Android ReactEditText marks itself textIsSelectable in onAttachedToWindow (a removeClippedSubviews workaround, react#6805), which makes the platform Editor treat every RN TextInput as read-only selectable text and skip its "Show the IME to be able to replace text" branch when a selection action mode starts (Editor#startActionModeInternal gates that branch on !isTextSelectable()). RN's own keyboard paths only cover clicks and programmatic focus, so long-pressing to select text in an unfocused input — or in a focused input after the keyboard was dismissed — left the user with a selection toolbar and no keyboard. Compensate in ReactEditText: request the keyboard when a selection or insertion action mode is created, and when focus is gained with a non-collapsed selection (the action mode can precede focus). Guarded by isEnabled (the editable prop), isInTouchMode, and showSoftInputOnFocus, mirroring both requestFocusProgrammatically() and the platform branch. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Hi @idoyana! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
@Abbondanzo has imported this pull request. If you are a Meta employee, you can view this in D110990211. |
Summary
On Android, long-pressing text in a
TextInputwhile the soft keyboard is hidden starts text selection (highlight + Cut/Copy toolbar) and focuses the field — but the soft keyboard never appears, leaving the user unable to type over the selection. This happens both when the input was unfocused and when it was focused with the keyboard dismissed.Root cause:
ReactEditText.onAttachedToWindow()callssuper.setTextIsSelectable(true)(aremoveClippedSubviewsworkaround, #6805). That makesisTextSelectable()returntrue, so the platformEditor#startActionModeInternal()skips its own "Show the IME to be able to replace text" branch — it is gated on!isTextSelectable()and deliberately skips read-only selectable text, which every RNTextInputnow masquerades as. RN's own keyboard paths cover only clicks and programmatic focus (see the comment onrequestFocusProgrammatically()); focus gained through long-press selection is a third path neither covers.Fix: compensate in
ReactEditText, mirroring the platform branch it opted out of —onCreateActionMode), andonFocusChanged) — the action mode can be created before the view becomes the IME-served view, so this re-requests once focus has landed.Both sites go through a shared guard (
isEnabled— theeditableprop maps to it,isInTouchMode,showSoftInputOnFocus) that mirrorsrequestFocusProgrammatically(), so read-only inputs andshowSoftInputOnFocus={false}are unaffected.showSoftInputis idempotent, so an already-visible keyboard is a no-op.Fixes #57470 (reproduced there with a bare
TextInputin a plainView, no third-party components).Changelog:
[ANDROID] [FIXED] - Show the soft keyboard when a long-press starts text selection in TextInput
Test Plan:
RNTester TextInput example on a Pixel 10 Pro (Android 16, Gboard),
-PreactNativeArchitectures=arm64-v8a:Before (main,
0015d1e4f9) — long-press a word in the prefilled "Default color text" field with the keyboard hidden:ImeTrackerevents;dumpsys input_method→mInputShown=falseAfter (this change) — same gestures:
ImeTracker: onRequestShow at ORIGIN_CLIENT reason SHOW_SOFT_INPUT→onShown;mInputShown=truefromUser=truerequest + RN's existing click path, same as before the change)EditTextbehavior./gradlew :packages:react-native:ReactAndroid:ktfmtCheckpasses.